package com.ljf.authority.api.service.impl;

import com.ljf.authority.domain.repository.AuthorityDatPermissionGroupRepository;
import com.ljf.authority.domain.service.AuthorityDatPermissionGroupDomainService;
import com.ljf.authority.domain.validator.AuthorityDatPermissionGroupValidator;
import com.ljf.authority.dto.command.AuthorityDatPermissionGroupCommand;
import com.ljf.authority.dto.command.AuthorityDatPermissionGroupMenuCommand;
import com.ljf.authority.dto.command.AuthorityDatPermissionGroupUserCommand;
import com.ljf.authority.dto.query.AuthorityDatPermissionGroupQuery;
import com.ljf.authority.model.AuthorityDatPermissionGroup;
import com.ljf.authority.service.IAuthorityDatPermissionGroupService;
import com.ljf.authority.vo.AuthorityDatPermissionGroupMenuVO;
import com.ljf.authority.vo.AuthorityDatPermissionGroupUserVO;
import com.ljf.authority.vo.AuthorityDatPermissionGroupVO;
import com.ljf.common.api.service.impl.BasisServiceImpl;
import com.ljf.common.exception.ServiceException;
import com.ljf.common.result.ServiceResultModel;
import com.ljf.common.utils.ServiceResultUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 权限组  服务接口实现
 *
 * @author LJF
 * @since 2025-06-08
 */
@Service
public class AuthorityDatPermissionGroupServiceImpl extends BasisServiceImpl<AuthorityDatPermissionGroupDomainService, AuthorityDatPermissionGroupValidator, AuthorityDatPermissionGroupRepository, AuthorityDatPermissionGroupQuery, AuthorityDatPermissionGroupVO, AuthorityDatPermissionGroup, AuthorityDatPermissionGroupCommand> implements IAuthorityDatPermissionGroupService {

    /**
     * 修改权限组菜单
     *
     * @param command
     * @return
     * @throws ServiceException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ServiceResultModel editMenu(AuthorityDatPermissionGroupMenuCommand command) throws ServiceException {
        validator.checkEditMenu(command);
        domainService.editMenu(command);
        return ServiceResultUtil.success();
    }

    /**
     * 修改权限组用户
     *
     * @param command
     * @return
     * @throws ServiceException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ServiceResultModel editUser(AuthorityDatPermissionGroupUserCommand command) throws ServiceException {
        validator.checkEditUser(command);
        domainService.editUser(command);
        return ServiceResultUtil.success();
    }

    /**
     * 查询权限组菜单
     *
     * @param id
     * @return
     * @throws ServiceException
     */
    @Override
    public ServiceResultModel<AuthorityDatPermissionGroupMenuVO> queryMenuById(Long id) throws ServiceException {
        validator.checkQueryMenuById(id);
        AuthorityDatPermissionGroupMenuVO result = domainService.queryMenuById(id);
        List<AuthorityDatPermissionGroupMenuVO> resultList = new ArrayList<>();
        resultList.add(result);
        return ServiceResultUtil.success(resultList);
    }

    /**
     * 查询权限组用户
     *
     * @param id
     * @return
     * @throws ServiceException
     */
    @Override
    public ServiceResultModel<AuthorityDatPermissionGroupUserVO> queryUserById(Long id) throws ServiceException {
        validator.checkQueryUserById(id);
        AuthorityDatPermissionGroupUserVO result = domainService.queryUserById(id);
        List<AuthorityDatPermissionGroupUserVO> resultList = new ArrayList<>();
        resultList.add(result);
        return ServiceResultUtil.success(resultList);
    }

}
